<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="${mapperPath}">
    <resultMap id="BaseResultMap" type="${entityPath}">
        <#list filedList as  filed>
            <#if "${filed.idFiled}"=="1">
                <id column ="${filed.column}"  property="${filed.name}" />
            <#elseif "${filed.exist}"=="1">
                <result column="${filed.column}"  property="${filed.name}" />
            </#if>
        </#list>
    </resultMap>

    <insert id="insertSelective" keyColumn="${idColumn}" keyProperty="${idFiled}" useGeneratedKeys="true" parameterType="${entityPath}">
        INSERT INTO ${table} <include refid= "insertSelectiveColumn"></include> <include refid= "insertSelectiveValue"></include>
    </insert>

    <sql id="columns">
        <#list filedList as  filed><#if "${filed.exist}"=="1"> <#if filed_index != 0> , </#if> ${filed.column} </#if></#list>
    </sql>

    <sql id="insert_columns">
         <#list filedList as  filed><#if "${filed.exist}"=="1"><#if filed_index != 0>  , </#if> ${filed.column}</#if></#list>
    </sql>

    <sql id="insert_values">
          <#list filedList as  filed><#if "${filed.exist}"=="1"><#if filed_index != 0>, </#if> ${r"#{"}${filed.name}${r"}"}</#if></#list>
    </sql>

    <sql id="insertSelectiveColumn">
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <#list filedList as  filed>
                <#if "${filed.exist}"=="1">
                    <if test="null!=${filed.name}">${filed.column},</if>
                </#if>
            </#list>
        </trim>
    </sql>

    <sql id="insertSelectiveValue">
        <trim prefix="values (" suffix=")" suffixOverrides=",">
             <#list filedList as  filed>
                 <#if "${filed.exist}"=="1">
                    <if test="null!=${filed.name}">${r"#{"}${filed.name}${r"}"},</if>
                 </#if>
             </#list>
        </trim>
    </sql>

    <sql id="updateByPrimaryKeySelectiveSql">
        <set>
             <#list filedList as  filed>
                  <#if "${filed.exist}"=="1"><if test="null!=${filed.name}"> ${filed.column} = ${r"#{"}${filed.name}${r"}"},</if></#if>
             </#list>
        </set>
    </sql>

   <sql id="where">
         <#list filedList as  filed>
              <#if "${filed.exist}"=="2">
                  <#if "${filed.startFileNameVal}"=="1">
                      <if test="null!=${filed.startFiledName} and null!=${filed.name}">AND ${filed.column} between ${r"#{"}${filed.startFiledName}${r"}"} and  ${r"#{"}${filed.name}${r"}"} </if>
                      <if test="null!=${filed.startFiledName} and null==${filed.name}">AND ${filed.column} <![CDATA[ >= ]]> ${r"#{"}${filed.startFiledName}${r"}"}  </if>
                      <if test="null==${filed.startFiledName} and null!=${filed.name}">AND ${filed.column} <![CDATA[ <= ]]> ${r"#{"}${filed.name}${r"}"} </if>

                  </#if>

                  <#elseif "${filed.startFileNameVal}"=="0">
                      <#if "${filed.exist}"=="1">
                             <if test="null!=${filed.name}">AND ${filed.column} = ${r"#{"}${filed.name}${r"}"}  </if>
                      </#if>
              </#if>

         </#list>
   </sql>
</mapper>